/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package wf3.hibernate;

import acceso.hibernate.AQuery;
import java.util.Date;
import org.hibernate.StatelessSession;

/**
 *
 * @author romulogalindo
 */
public class Aquery2 {

//    private AQuery query;
    private long id_sesion;
    private int id_transa;
    private int id_frawor;
    private int co_pagina;
    private int co_type;
    private String no_query;
    private Date fe_;
    private Date fe_2;
    public static int TRAPAGINI = 1;
    public static int TRAPAGFIN = 2;
    public static int TRACONFIN = 3;
    public static int TRANSAFIN = 4;
    public static int TRAPAGVIS = 5;

    public Aquery2(long id_sesion, int id_transa, int id_frawor, int co_pagina, int co_type) {
        this(id_sesion, id_transa, id_frawor, co_pagina, null, co_type);
    }

    public Aquery2(long id_sesion, int id_transa, int id_frawor, int co_pagina, Date fe_, int co_type) {
        this(id_sesion, id_transa, id_frawor, co_pagina, fe_, null, co_type);
    }

    public Aquery2(long id_sesion, int id_transa, int id_frawor, int co_pagina, Date fe_, Date fe_2, int co_type) {
        this.id_sesion = id_sesion;
        this.id_transa = id_transa;
        this.id_frawor = id_frawor;
        this.co_pagina = co_pagina;
        this.co_type = co_type;
        this.fe_ = fe_;
        this.fe_2 = fe_2;
    }

    public AQuery getAquery(StatelessSession session) {
        AQuery query = null;
        switch (co_type) {
            case 1:
                query = new AQuery(session.getNamedQuery(getNo_query()), id_sesion);
                query.setInteger("p_id_transa", id_transa);
                query.setInteger("p_id_frawor", id_frawor);
                query.setInteger("p_co_pagina", co_pagina);
                break;
            case 2:
                query = new AQuery(session.getNamedQuery(getNo_query()), id_sesion);
                query.setInteger("p_id_transa", id_transa);
                query.setInteger("p_co_pagina", co_pagina);
                break;
            case 3:
                query = new AQuery(session.getNamedQuery(getNo_query()), id_sesion);
                query.setInteger("p_id_transa", id_transa);
                break;
            case 4:
                query = new AQuery(session.getNamedQuery(getNo_query()), id_sesion);
                query.setInteger("p_id_transa", id_transa);
                query.setTimestamp("p_fe_solfin", fe_);
                break;
            case 5:
                query = new AQuery(session.getNamedQuery(getNo_query()), id_sesion);
                query.setInteger("p_id_transa", id_transa);
                query.setInteger("p_id_frawor", id_frawor);
                query.setInteger("p_co_pagina", co_pagina);
                query.setTimestamp("p_fe_visini", fe_);
                query.setTimestamp("p_fe_visfin", fe_2);
                break;
        }

        return query;
    }

    public int getId_transa() {
        return id_transa;
    }

    public void setId_transa(int id_transa) {
        this.id_transa = id_transa;
    }

    public int getId_frawor() {
        return id_frawor;
    }

    public void setId_frawor(int id_frawor) {
        this.id_frawor = id_frawor;
    }

    public int getCo_pagina() {
        return co_pagina;
    }

    public void setCo_pagina(int co_pagina) {
        this.co_pagina = co_pagina;
    }

    public int getCo_type() {
        return co_type;
    }

    public void setCo_type(int co_type) {
        this.co_type = co_type;
    }

    public String getNo_query() {
        switch (this.co_type) {
            case 1:
                no_query = "frawor2.pptrapagini";
                break;
            case 2:
                no_query = "frawor2.pptrapagfin";
                break;
            case 3:
                no_query = "frawor2.pptraconfin";
                break;
            case 4:
                no_query = "frawor2.pptransafin";
                break;
            case 5:
//                no_query = "update fratra.tptrapag set fe_visini=:p_fe_visini , fe_visfin =:p_fe_visfin where id_transa = :p_id_transa and id_frawor = :p_id_frawor and co_pagina = :p_co_pagina ";
                no_query = "frawor2.pptrapagvis";
                break;
        }
        return no_query;
    }

    public long getId_sesion() {
        return id_sesion;
    }

    public void setId_sesion(long id_sesion) {
        this.id_sesion = id_sesion;
    }

}
